package Test;

import java.util.Scanner;

public class YongHuDengLu {
    public static void main(String[] args) {
        //用户登录
        //已知正确的用户和密码，请用程序实现模拟用户登录
        //总共给出三次机会，登录之后，给出相应的提示

        //1.定义正确的用户和密码
        String rightUsername = "zhangsan";
        String rightPassword = "123456";

        //4.三次机会，循环和提示
        Scanner sc = new Scanner(System.in);
        for (int i = 1; i <= 3; i++) {

            //2.请用程序实现模拟用户登录，键盘录入
            System.out.println("请输入用户名：");
            String Username = sc.next();
            System.out.println("请输入密码：");
            String Password = sc.next();

            //3.比较
            boolean resultname = rightUsername.equals(Username);
            boolean resultpassword = rightPassword.equals(Password);
            if (resultname && resultpassword){
                System.out.println("登录成功！");

                break;
                } else {
                    if (i == 3){
                        System.out.println("次数已用完，账号已锁定，请联系客服小姐姐");
                    }else {
                        System.out.println("输入错误，你还有" + (3 - i) + "次输入机会");
                    }

                }
            }
    }
}

